package com.example.demo.oo.repository;

import com.example.demo.app.cache.Cache;
import com.example.demo.oo.domain.Captcha;
import org.springframework.stereotype.Repository;

@Repository
public class CaptchaRepository {

    private Cache<String, Captcha> cache = new Cache<>(Captcha.getExpire());

    public Captcha find(Captcha captcha) {
        return cache.get(captcha.cacheKey());
    }

    public void save(Captcha captcha) {
        cache.put(captcha.cacheKey(), captcha);
    }

    public void delete(Captcha captcha) {
        cache.invalidate(captcha.cacheKey());
    }
}
